﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FileManager_UnInstall.Properties;

namespace FileManager_UnInstall
{
    public partial class Uninstall : Form
    {
        public Uninstall()
        {
            InitializeComponent();
            var installPath = Path.Combine(Path.GetTempPath(), "FilemanagerUnInstallFolder");
            if (!Directory.Exists(installPath))
                Directory.CreateDirectory(installPath);

            var globalPath = Path.Combine(installPath, "FileManagerGlobal_Library.dll");
            File.WriteAllBytes(globalPath, Resources.FileManagerGlobal_Library);

            var unInstallPath = Path.Combine(installPath, "FileManager_UnInstallDelete.exe");
            File.WriteAllBytes(unInstallPath, Resources.FileManager_UnInstallDelete);

            var starInfo = new ProcessStartInfo
                               {FileName = unInstallPath, Arguments = "\""+Application.StartupPath+"\"", LoadUserProfile = true};
            Process.Start(starInfo);
            Environment.Exit(Environment.ExitCode);
        }

        #region hide application
        private bool _windowCreate = true;
        protected override void OnActivated(EventArgs e)
        {

            if (_windowCreate)
            {
                base.Visible = false;
                _windowCreate = false;
            }
            base.OnActivated(e);
        }
        protected override CreateParams CreateParams
        {
            get
            {
                var WS_EX_TOOLWINDOW = 0x80;
                var CP = base.CreateParams;
                CP.ExStyle = CP.ExStyle | WS_EX_TOOLWINDOW;
                return CP;
            }
        }
        #endregion
    }
}
